/**
 * AccountBind
 * @authors 杨兴洲（of2502）
 * @date    2017/5/23 0023 11:31
 * @version 1.0
 * @last-modify  杨兴洲（of2502）
 */

import React, {Component} from 'react';
import {Map} from 'immutable';
import {Relax} from 'iflux2';
import {Button} from "antd";
import BindWaitingModal from '../../main/component/BindWaitingModal';

@Relax
class AccountBind extends Component {

    static defaultProps = {
        fetchAuthUrl: () => void 0,
        authUrl: "javascript:;",
        userInfo: Map()
    };

    constructor(props) {
        super(props);
        this.state = {
            visible: false,
            canClick: false
        };
    }

    componentDidMount() {
        this.props.fetchAuthUrl().then(data => {
            this.setState({
                canClick: true
            })
        });
    }

    componentDidUpdate() {
        // if (this.props.userInfo.get("appid")) {
            // console.log(this.props.userInfo.toJS());
            // location.href = "/#/overview";
        // }
    }

    render() {
        return (
            <div className="AccountBind">
                <div className="intro">
                    <h3>绑定微信公众号，把商城和微信打通</h3>
                    <p>绑定后即可在这里管理你的公众号，千米提供比微信官方后台更强大的功能。</p>
                </div>
                <Button type="primary" loading={!this.state.canClick} size="large" style={{marginTop: 20}}
                        onClick={this.goToAuth}>立即绑定</Button>
                {/*<a className="btn" style={{marginTop: 20}} href="javascript:;" onClick={this.goToAuth}>立即绑定</a>*/}
                <BindWaitingModal ref={modal => this.modal = modal} authUrl={this.props.authUrl}/>
            </div>
        )
    }

    goToAuth = () => {
        if (!this.state.canClick) return;
        this.modal.goToAuth();
    }
}

export default AccountBind;